home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Info-Mac 4
/
Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso
/
Development
/
General
/
CIncludesTool
/
modified version
/
source files
/
locate.c
< prev
next >
Wrap
Text File
|
1991-08-28
|
1KB
|
67 lines
// locate.c
//
// searching functions for CIncludesCode MPW tool
#include <Memory.h>
#include <StdIO.h>
#include <String.h>
#include "CIncludesCode.h"
extern Handle database;
extern dataHeaderType dataHeader;
char *getDictionaryPtr(char ch)
{
long offset;
offset = dataHeader.dictionaryOffsets[dictionaryIndex(ch)];
return (StripAddress(*database) + offset);
} // getDictionaryPtr()
char *getNamePtr(short index)
{
strArray *sp = (strArray*) (*database + dataHeader.nameArrayOffset);
return ((char*) ((*sp)[index]));
} // getNamePtr()
char *search(char *s,char* dictPtr)
// returns pointer or NIL
{
char *p = dictPtr + (4 + 2 + 4); // endOffset = 4,fileIndex = 2,filePosition = 4
char *limit = dictPtr + *((long*) dictPtr);
if (*s)
{
while (p < limit)
{
if (strcmp(p,s) == 0)
{
return (p - (2 + 4)); // fileIndex = 2,filePosition = 4
} // if strcmp()
else
{
p += strlen(p) + (2 + 4 + 1); // fileIndex = 2,filePosition = 4,'\0' = 1
} // else if strcmp()
} // while p
} // if *s
return 0;
} // search()
Boolean locateIdentifier(char *dest,long *filePosition,char *src)
{
char *entryPtr = search(src,getDictionaryPtr(*src));
char *p;
if (entryPtr)
{
p = getNamePtr(getShort(entryPtr));
strcpy(dest,p);
*filePosition = getLong(entryPtr + 2);
} // if entryPtr
return ((Boolean) entryPtr);
} // locateIdentifier()
// end of locate.c